package com.ss.android.article.browser.view;

import android.os.Build;
import android.view.View;

import java.util.concurrent.atomic.AtomicInteger;

public final class ViewIdGenerator {
    private static final AtomicInteger lastId = new AtomicInteger(1);

    public static int generate() {
        int v0;
        int v1;
        if (Build.VERSION.SDK_INT <= 18) {
            do {
                v1 = ViewIdGenerator.lastId.get();
                v0 = v1 + 1;
                if (v0 > 16777215) {
                    v0 = 1;
                }
            } while (!ViewIdGenerator.lastId.compareAndSet(v1, v0));
            v0 = v1;
        } else {
            v0 = View.generateViewId();
        }

        return v0;
    }
}

